package com.pfzy.eventbusdemo

import android.os.Bundle
import android.util.Log
import androidx.annotation.Nullable
import androidx.appcompat.app.AppCompatActivity
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class StickyActivity : AppCompatActivity() {
    override fun onCreate(@Nullable savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_sticky)
        EventBus.getDefault().register(this)
    }

    override fun onDestroy() {
        super.onDestroy()
        EventBus.getDefault().unregister(this)
    }

    /**
     * 接收 StickyEvent
     */
    @Subscribe(sticky = true, threadMode = ThreadMode.POSTING)
    fun onPostingEvent(event: MyStickyEvent?) {
        Log.d(TAG, "onPostingEvent:" + Thread.currentThread().name)
    }

    companion object {
        private const val TAG = "StickyActivity"
    }
}